<template>
	<view class="container">
		<u-navbar title="登录" bgColor="transparent">
			<view class="" slot="left" @click="onBack">
				<u-icon name="arrow-left" color="#000" size="20"></u-icon>
			</view>
		</u-navbar>
		<view class="header-bg"></view>
		<view class="content-box">
			<image class="logo" style="width: 84rpx;height: 80rpx;" src="../../../static/logo.png" mode=""></image>
			<view class="tips">来E萌宠分享你的爱宠乐趣</view>
			<u-button :loading='loginLoading' @click="onWxLogin" shape="circle"
				:customStyle="{width:'614rpx',height:'88rpx',marginBottom:'20px'}" class="btn-wx-login" type="success"
				text="微信一键登录"></u-button>
			<u-checkbox-group v-model="checked">
				<u-checkbox name='选择' shape="circle" label="我已阅读并同意"></u-checkbox>
				<a @click="jumpPrivacyPolicy">《E萌宠隐私政策》</a>
			</u-checkbox-group>
		</view>
	</view>
</template>

<script>
	import loginVue from './login.vue'
	import {
		mapState,
		mapActions
	} from 'vuex';
	export default {
		data() {
			return {
				loginLoading: false,
				type: '',
				checked: ['选择']
			}
		},
		onLoad(options) {
			if (options.type) {
				this.type = options.type
			}
		},
		methods: {
			...mapActions(['setToken', 'setUserinfo']),
			jumpPrivacyPolicy() {
				this.$Jump.Open('/pages/mine/login/privacyPolicy')
			},
			onBack() {
				if (this.type == 'home') {
					uni.switchTab({
						url: '/pages/index/index'
					})
				} else {
					this.$Jump.Back();
				}
			},
			onWxLogin() {
				if (this.checked.length == 0) {
					this.$Msg.Toast('请先阅读并同意E萌宠隐私政策')
					return
				}
				let _this = this;
				this.loginLoading = true;
				uni.login({
					provider: 'weixin',
					success(res) {
						_this.$Net.get(_this.$api.silence_auth_login, {
							code: res.code
						}, 1).then(async lRes => {
							console.log('---------', lRes);
							_this.setToken(lRes.token)
							await _this.getUserInfo();
							_this.loginLoading = false;
							_this.$Jump.Back()
						}).catch(er => {
							_this.loginLoading = false;
						})
						console.log('-', res);
					},
					fail() {
						_this.loginLoading = false;
					}
				})
			},
			getUserInfo() {
				this.$Net.get(this.$api.user_info, {}, 1).then(res => {
					console.log('---------', res);
					this.setUserinfo(res)
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		padding: 0;
	}

	.header-bg {
		width: 100%;
		height: 426rpx;
		background-color: #70B5FE;
		position: absolute;
		top: 0;
		left: 0;
	}

	.content-box {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 426rpx;

		.logo {
			margin-bottom: 50rpx;
			margin-top: 50rpx;
		}

		.tips {
			color: rgba(0, 0, 0, 0.80);
			text-align: center;
			font-family: "PingFang SC";
			font-size: 32rpx;
			font-weight: 400;
			line-height: 48rpx;
			/* 150% */
			margin-bottom: 80rpx;
		}

		.btn-wx-login {
			width: 600rpx;
		}

		a {
			display: inline-block;
			color: #68B0FC;
		}
	}
</style>